package com.example.study.rabbitmq.chat;

import com.alibaba.fastjson.JSON;
import com.example.study.plus.mybatis_plus.entity.ChatMessages;
import com.example.study.plus.mybatis_plus.service.ChatMessagesService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Arrays;

@Slf4j
@Component
public class ChatReceiveHandler {

    @Resource
    ChatMessagesService chatMessagesService;


    @RabbitListener(queues = "chat_que")
    public void receive_email_(ChatMessages msg, Message message, Channel channel) throws IOException {
//        ChatMessages chatMessages = JSON.parseObject(msg.toString(), ChatMessages.class);
        log.info("应答:聊天 " + message.getMessageProperties().getConsumerQueue() + "\n" + msg.getMessage());

        chatMessagesService.sendAMessage(msg);

    }
    @RabbitListener(queues = {"dead_que"})
    public void receive_dead_(Object msg, Message message, Channel channel) {

        log.info("应答:死信 " + message.getMessageProperties().getConsumerQueue() + "__:" + msg);

    }
}
